import { Label, tween, Vec3, color } from "cc";
import FragmentManager from "../FragmentManager";
import Toast from "../view/Toast";
import { Fragment } from "./Fragment";

export class NotifyFragment extends Fragment {

    /**
     * 显示toast
     * @param content 文本表示
     * @param useI18n 是否使用多语言
     */
    show(manager: FragmentManager, content: string, useI18n: boolean): void {
        manager.open(Toast, {
            onAdd(manager, view, node) {
                const label = node.getComponent(Label);
                if (label) {
                    label.string = content;
                }
            },
        }).then((result) => {
            // console.log(' >>. 1 ')
            // if (result) {
            //     this.scheduleOnce(() => {
            //         console.log(' >>. 2 ')
            //         
            //     }, 2)
            // }

            if (!result) return;
            //添加动画
            const [view, node] = result
            tween(node)
                .by(1, { position: new Vec3(0, 0, 0) })
                .by(0.5, { position: new Vec3(0, 150, 0) })
                .call(() => {
                    manager.remove(view);
                })
                .start()

            // .parallel(
            //     tween(node).to(1, { position: new Vec3(100, 100, 0) }),
            //     tween(node.getComponent(UITransform) as UITransform).to(1, { contentSize: size(100, 100) }),
            //     tween(node.getComponent(Sprite) as Sprite).to(1, { color: color(100, 100, 100, 100) }),
            // )

            // tween(node)
            //     .to(1, { position: new Vec3(node.position.x, node.position.y + 150, node.position.z) })
            //     .parallel(
            //         tween(node).by(1, { scale: new Vec3(-0.5, -0.5, 0) }),
            //         tween(node.getComponent(Label)).by(1, { color: color(0, 0, 0, -100) }),
            //     )
            //     .call(() => {
            //         manager.remove(view);
            //     })
            //     .start();


        })
    }
}